

<template>
  <div>
    <el-popover :placement="placement" v-model="params.show" trigger="focus">
      <el-input
        :placeholder="thatF.setSelectInput.placeholder"
        slot="reference"
        v-model="thatF.setSelectInput.keyword"
        size="mini"
        @input="getSeach()"
      >
      </el-input>

      <el-table
        v-loading="params.loading"
        @current-change="querySelect"
        highlight-current-row
        height="300"
        :data="params.data"
      >
        <template>
          <span v-for="(item, index) in thatF.setSelectInput.list" :key="index">
            <el-table-column
              :prop="item.prop"
              :label="item.label"
              :width="item.width"
            >
            </el-table-column>
          </span>
        </template>
        <!-- <el-table-column type="index" label="序号" width="50">
            </el-table-column>
           -->
      </el-table>

      <el-pagination
        :current-page="params.page"
        :page-size="params.limit"
        @current-change="selectPage"
        :total="params.count"
        layout="prev, pager, next"
      >
      </el-pagination>
    </el-popover>
  </div>
</template>
<script>
let t;

import ViewTitle from "@/forComponents/viewTitle/index.vue";
import { mapState, mapActions } from "vuex";
export default {
  // props: ["thatF","type"],
  props: {
    thatF: {
      type: Object,
    },
    type: {
      type: String,
    },
    placement: {
      type: String,
      default: "bottom-end",
    },
  },
  data() {
    return {
      setSelectInput: "setSelectInput",

      params: {
        show: false,

        page: 1,
        limit: 20,
        loading: false,
        data: [],
        count: 0,
      },
    };
  },
  mounted() {
    t = this;

    t.getList();
  },

  methods: {
    getSeach() {
      this.params.page = 1;
      this.getList();
      if (this.thatF.setSelectInput.statusdoctor) {
        this.thatF.setSelectInput.id = "";

        t.thatF.getdoctorList();
      }
    },

    getList() {
      this.params.loading = true;
      let d = {
        keyword: this.thatF.setSelectInput.keyword,
        page: this.params.page,
        limit: this.params.limit,
      };
      if (t.thatF.setSelectInput.key == "huajia_patient") {
        // d.register_doctor=1;
        d.from = "clinic_fee";
        d.status = 3;
      }
      t["_API"][t.thatF.setSelectInput.url](d).then((res) => {
        this.params.loading = false;
        console.log("ress", res);
        if (res.code == 200) {
          switch (t.thatF.setSelectInput.key) {
            case "yisheng":
              this.params.data = res.data.list.map((v) => {
                return {
                  Name_B: v.doctor.real_name,
                  Id_B: v.doctor.id,
                  ...v,
                };
              });
              break;
            //   case 'mantebin':
            //    this.params.data = res.data.list.map(v=>{
            //       return {
            //         Name_B:v.name,
            //         Id_B:v.id,
            //         ...v,
            //       }
            //     });
            //  break;
            case "mantebing":
              this.params.data = res.data.list.map((v) => {
                return {
                  Name_B: v.name,
                  Id_B: v.m_code,
                  ...v,
                };
              });
              break;
            case "patient":
              this.params.data = res.data.list.map((v) => {
                return {
                  Name_B: v.name,
                  Id_B: v.id,
                  ...v,
                };
              });
              break;
            case "zhengduan":
              this.params.data = res.data.lists.map((v) => {
                return {
                  Name_B: v.name,
                  Id_B: v.id,
                  ...v,
                };
              });
              break;
            case "huajia_patient":
              this.params.data = res.data.list.map((v) => {
                return {
                  Name_B: v.member_info.name,
                  Id_B: v.member_info.id,
                  ...v,
                };
              });
              break;
            case "keshi":
              this.params.data = res.data[0].children.map((v) => {
                return {
                  Name_B: v.name,
                  Id_B: v.id,
                  ...v,
                };
              });
              break;
            default:
              this.params.data = res.data.list.map((v) => {
                return {
                  Name_B: v.real_name,
                  Id_B: v.id,
                  ...v,
                };
              });
              break;
          }

          console.log(" this.params.data ", this.params.data);

          this.params.count = res.data.count;
        }
      });
    },

    selectPage(e) {
      this.params.page = e;
      this.getList();
    },

    querySelect(item) {
      if (!item) {
        return;
      }
      this.thatF.setSelectInput.keyword = item.Name_B;
      this.thatF.setSelectInput.id = item.Id_B;

      if (this.thatF.setSelectInput.statusdoctor) {
        t.thatF.params.doctorReal_name = "";
        t.thatF.getdoctorList();
      }
      //诊断
      if (t.thatF.setSelectInput.key == "zhengduan") {
        //  this.thatF.setSelectInput.code=item.code;
        this.thatF.setSelectInput.keyword = "";
        this.thatF.setSelectInput.tableData1 =
          this.thatF.setSelectInput.tableData1.concat(item);
        this.thatF["doctorWorkStation/set_tableData1"](
          this.thatF.setSelectInput.tableData1
        );
      }
      if (t.thatF.setSelectInput.key == "huajia_patient") {
        console.log("item", item.member_info.gender);
        item.member_info.gender = item.member_info.gender.toString(); //药房划价
        this.thatF.setSelectInput.detail = item;
      }

      if (t.thatF.setSelectInput.key == "patient") {
        //  console.log('item',item.member_info.gender)

        this.thatF.params.cert_no = item.id_card;
      }
      this.params.show = false;
    },
  },
};
</script>
<style lang='scss' scoped>
</style>
